package com.thesharegame.dal.search;

import java.util.ArrayList;
import java.util.List;

import com.thesharegame.model.Stock;

public class StockSQLGenerator implements SQLGenerator{

	@Override
	public String getSQL(Object object) {
		Stock stock = (Stock)object;
		List<String> criteria = new ArrayList<String>();
		
		String hql = "FROM Stock s";
		
		if(stock.getName() != null && !stock.getName().isEmpty()){
			criteria.add(" s.name=" + "'" +stock.getName() + "'");
		}
		
		if(stock.getSymbol() != null && !stock.getSymbol().isEmpty()){
			criteria.add(" s.symbol=" + "'" +stock.getSymbol() + "'");
		}
		
		
		if(!criteria.isEmpty()){
			hql = hql + " WHERE";
			hql = hql + criteria.get(0);
			for(int i = 1;i < criteria.size();i++){
				hql = hql + " AND" + criteria.get(i);
			}
		}
		
		return hql;
	}

}
